import javax.swing.*;

import javax.swing.event.*;


public class Jeu extends JFrame implements ChangeListener{
 
	private JSlider slider;
	private MonContainer container;
	public String [][] map1;
	public static String faction;
	private int numFaction=0;
	private boolean stopTour=false;
	
	//============CONSTRUCTEUR===================
	public Jeu (String nomMap) {
		super("Advance War");
 
		slider = new JSlider(JSlider.HORIZONTAL,0,100,100);
		slider.setMajorTickSpacing(10);
		slider.setMinorTickSpacing(5);
		slider.setPaintTicks(true);
        slider.addChangeListener(this);
		
		this.map1=new String[20][15];
		this.map1=Map.chargementMap(nomMap);    //new String[nbLi][nbCol];
		
        container = new MonContainer(this.getLayeredPane(), this.map1);
		this.setContentPane(container);
 
		this.pack();
		this.setResizable(false);
		this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
		this.show();
		
		do {
			
			for(Unite u : MonContainer.a.lesArmees)
			{
				u.joueCombat=false;
				u.joueMouv=false;
			}
			
			this.faction=null;
			
			if(numFaction==4) numFaction=0;
			if(numFaction==0 && Jeu.isResteUnite("Red") ) this.faction="Red";
			else if(numFaction==1 && Jeu.isResteUnite("Blue")) this.faction="Blue";
			else if(numFaction==2 && Jeu.isResteUnite("Green")) this.faction="Green";
			else if(numFaction==3 && Jeu.isResteUnite("Yellow")) this.faction="Yellow";
			
			if(faction!=null)
			{
				JOptionPane.showMessageDialog(null,"Joueur "+this.faction+".");
				do {
					MonContainer.stopTour=false;
					
					try { Thread.sleep(100); }
					catch (Exception e) {}
					
					stopTour=MonContainer.stopTour;				
				} while(stopTour==false);
			}
			
			numFaction++;
			
		} while(true);
	}
	//====================METHODE===========================
	public void stateChanged(ChangeEvent e) {}
	
	public static boolean isResteUnite(String numFaction)
	{
		boolean resteUnite=false;
		
		for(Unite u : MonContainer.a.lesArmees)
		{
			if(u.getFaction().equals(numFaction) ) resteUnite=true;
		}
		return resteUnite;
	}
	//=========================MAIN==========================
	public static void main (String args[]) {
 
		try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); }
		catch (Exception e) {}
		new Jeu(args[0]);
	}
}